package tech.lq0.mineapex.registry;

import net.minecraft.item.ItemModelsProperties;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import tech.lq0.mineapex.MineApex;
import tech.lq0.mineapex.armor.EvoShield;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class PropertyRegistry {
    @SubscribeEvent
    public static void propertyOverrideRegistry(FMLClientSetupEvent event) {
        event.enqueueWork(() -> ItemModelsProperties.registerProperty(ItemRegistry.EVO_SHIED.get(), new ResourceLocation(MineApex.MOD_ID, "max_armor"), (itemStack, clientWorld, livingEntity) -> {
            if (itemStack.getChildTag("evo") != null) {
                CompoundNBT nbt = itemStack.getStack().getOrCreateChildTag("evo");
                return nbt.getFloat("max");
            }
            return EvoShield.shield[0];
        }));
        event.enqueueWork(() -> ItemModelsProperties.registerProperty(ItemRegistry.EVO_SHIED.get(), new ResourceLocation(MineApex.MOD_ID, "is_inf_armor"), (itemStack, clientWorld, livingEntity) -> {
            if (itemStack.getChildTag("evo") != null) {
                CompoundNBT nbt = itemStack.getStack().getOrCreateChildTag("evo");
                return (nbt.getFloat("max") == Float.POSITIVE_INFINITY || nbt.getFloat("current") == Float.POSITIVE_INFINITY) ? 1 : 0;
            }
            return 0;
        }));
    }
}
